import { Component } from "react";

class Tiger extends Component {
  constructor(props) {
    super(props);
    let f = this.first;
    // 在构造函数中通过 bind 为事件监听器绑定 this
    this.first = f.bind( this );
    console.log( this.first === f );
  }
  render(){
    return (
        <div className="wrapper">
            <p>为事件监听器绑定 this</p>
            <button onClick={ this.first }>first</button>
            <button onClick={ () => this.second() }>second</button>
            <button onClick={ this.third.bind(this) }>third</button>
            <button onClick={ this.third.bind(this) }>fourth</button>
        </div>
    )
  }
  first(){
    console.log( 'this: ' , this);
  }
  second(){
    console.log( 'this: ' , this);
  }
  third(){
    console.log( 'this: ' , this);
  }
  fourth = () =>{
    console.log( 'this: ' , this);
  }
}

export default Tiger ;